﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace LyyCMS.Migrations
{
    public partial class add_comment : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Title",
                table: "Blogs",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Category",
                table: "Blogs",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<DateTime>(
                name: "Create_At",
                table: "Blogs",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "Comments",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BlogId = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: true),
                    Comment = table.Column<string>(nullable: true),
                    Create_At = table.Column<DateTime>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Comments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Comments_Blogs_BlogId",
                        column: x => x.BlogId,
                        principalTable: "Blogs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "Blogs",
                columns: new[] { "Id", "Category", "Content", "Create_At", "Title" },
                values: new object[] { 1, 3, "net core need", new DateTime(2019, 10, 15, 17, 11, 35, 138, DateTimeKind.Local).AddTicks(307), "net core" });

            migrationBuilder.InsertData(
                table: "Blogs",
                columns: new[] { "Id", "Category", "Content", "Create_At", "Title" },
                values: new object[] { 2, 5, "ef core need", new DateTime(2019, 10, 15, 17, 11, 35, 140, DateTimeKind.Local).AddTicks(308), "ef core" });

            migrationBuilder.InsertData(
                table: "Comments",
                columns: new[] { "Id", "BlogId", "Comment", "Create_At", "Title" },
                values: new object[,]
                {
                    { 1, 1, "我不会用", new DateTime(2019, 10, 15, 17, 11, 35, 150, DateTimeKind.Local).AddTicks(314), "Net core is good" },
                    { 2, 1, "我会用", new DateTime(2019, 10, 15, 17, 11, 35, 150, DateTimeKind.Local).AddTicks(314), "Net core is not good" },
                    { 3, 2, "我不会用11", new DateTime(2019, 10, 15, 17, 11, 35, 150, DateTimeKind.Local).AddTicks(314), "ef core is good" },
                    { 4, 2, "我会用22", new DateTime(2019, 10, 15, 17, 11, 35, 150, DateTimeKind.Local).AddTicks(314), "ef core is not good" }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Comments_BlogId",
                table: "Comments",
                column: "BlogId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Comments");

            migrationBuilder.DeleteData(
                table: "Blogs",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Blogs",
                keyColumn: "Id",
                keyValue: 2);

            migrationBuilder.DropColumn(
                name: "Category",
                table: "Blogs");

            migrationBuilder.DropColumn(
                name: "Create_At",
                table: "Blogs");

            migrationBuilder.AlterColumn<string>(
                name: "Title",
                table: "Blogs",
                nullable: true,
                oldClrType: typeof(string));
        }
    }
}
